package tech.yunland.shop.web;

import com.moyuer.bsf.common.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.yunland.shop.domain.model.Exam;
import tech.yunland.shop.domain.model.ExamDescription;
import tech.yunland.shop.domain.service.ExamDescriptionService;

import java.util.List;

/**
 * Created by v on 17-7-6.
 */
@RestController
@RequestMapping("/exam_description")
public class ExamDescriptionController {

    @Autowired
    private ExamDescriptionService examDescriptionService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ExamDescription save(@RequestParam String des) {
        return examDescriptionService.save(des);
    }

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Pagination<ExamDescription> get(@RequestParam(required = false) String param,
                                           @RequestParam(required = false) Integer page,
                                           @RequestParam(required = false) Integer rows) {
        Pagination result = new Pagination(page, rows);
        Integer startIdx = result.getStartIdx();
        Integer count = examDescriptionService.getSize(param);
        List<ExamDescription> records = examDescriptionService.get(param, startIdx, rows);
        result.setCount(count);
        result.setRecords(records);
        return result;
    }
}
